/*****************************************************************************
*  @file     Example.h                                                       *
*  @brief    两数之和                                                              *
*                                                                            *
*  @author   kerwin                                                          *
*  @email    jiawei24714.com                                                 *
*  @version  1.0.0.1                                                         *
*  @date     2021/06/17 09:19:15                                             *
*                                                                            *
*----------------------------------------------------------------------------*
*  Remark         : Description                                              *
*----------------------------------------------------------------------------*
*  Change History :                                                          *
*  <Date>     | <Version> | <Author>    | <Description>                      *
*----------------------------------------------------------------------------*
*  2021/06/17 | 1.0.0.1   | kerwin      | Create file                        *
*----------------------------------------------------------------------------*
*                                                                            *
*****************************************************************************/

#include<bits/stdc++.h>
using namespace std;


/**
 * @brief 哈希表 
 */
class Solution1 {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int,int> m;
        vector<int> ans;
        for(int i=0;i<nums.size();i++){
            if(m.find(target-nums[i]) == m.end()){
                m[nums[i]] = i;
            }
            else{
                ans.push_back(i);
                ans.push_back(m[target-nums[i]]);
                break;
            }
        }
        return ans;
    }
};


int main(){
    vector<int> nums={1,2,3,4};
    int target = 5;
    Solution1().twoSum(nums,target);
}